<!DOCTYPE html>
<html>

<head>
    <title>初次使用 canvas 绘图</title>
</head>

<script lang="javascript">
    function draw() {
        var canvas = document.getElementById("output");
        var context = canvas.getContext("2d");
        context.moveTo(0, 0);
        context.lineTo(500, 500);
        context.stroke();
    }
    window.onload = init;
</script>

<style type="text/css">
    canvas {
        border: 1px solid black;
    }
</style>

<body onload="draw()">
    <canvas id="output" height="500" width="500"></canvas>
</body>

</html>